package com.doctor.windflower_doctor.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;

import com.doctor.windflower_doctor.R;
import com.doctor.windflower_doctor.entity.QuestionBeen;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PopAdapter extends BaseAdapter {
	private Context context;
	private List<QuestionBeen> list;
	private LayoutInflater inflater;
	private int position;
	public PopAdapter(Context context) {
		this.context = context;
		this.inflater = LayoutInflater.from(context);
		this.list = new ArrayList<QuestionBeen>();
	}

	public void setData(List<QuestionBeen> list) {
		this.list = list;
	}

	public void addData(List<QuestionBeen> data) {
		if (data != null) {
			list.addAll(data);
			notifyDataSetChanged();
		}
	}
	public void setSelector(int position){
		this.position=position;
	}
	public void clear() {
		if (list != null) {
			list.clear();
		}
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder=null;
		if(convertView==null){
			holder=new ViewHolder();
			convertView=inflater.inflate(R.layout.list_item_popupwindow, arg2,false);
			holder.textView=(TextView) convertView.findViewById(R.id.tv_list_item);
			convertView.setTag(holder);
		}
		else {
			holder=(ViewHolder) convertView.getTag();
		}
		holder.textView.setText(list.get(arg0).name);
		LinearLayout layout = (LinearLayout) convertView;
		layout.setBackgroundResource(R.drawable.selector);
		/*holder.textView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				
			}
		});*/
		LinearLayout layouts = (LinearLayout) convertView;
		if(position==arg0){
			
			layouts.setBackgroundResource(R.drawable.selector);
		}else {
			layouts.setBackgroundResource(0);
		}
		return convertView;
	}
	class ViewHolder {
		TextView textView;
	}

}


